package com.zmn.oms.zmn.business.impl.chan;

import com.zmn.oms.model.entity.chan.plat.ChannelInterface;
import com.zmn.oms.model.entity.chan.plat.ChannelInterfaceQuery;
import com.zmn.oms.services.interfaces.chan.plat.ChannelInterfaceService;
import com.zmn.oms.zmn.business.interfaces.chan.ChannelInterfaceBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * 类描述：
 *
 * @author LiangHailong
 * @date 2022/02/18 15:36
 */
@Service("channelInterfaceBService")
public class ChannelInterfaceBServiceImpl implements ChannelInterfaceBService {

    @Autowired
    private ChannelInterfaceService channelInterfaceService;

    /**
     * 通过渠道ID查询
     * @param channelId
     * @return
     */
    @Override
    public Optional<ChannelInterface> findByChannelId(Integer channelId) {
        if (channelId == null) {
            return null;
        }
        ChannelInterfaceQuery query = new ChannelInterfaceQuery();
        query.setChannelId(channelId);
        List<ChannelInterface> channelInterfaces = channelInterfaceService.listByQuery(query);

        return Optional.ofNullable(channelInterfaces)
                .map(list -> list.isEmpty() ? null : list.get(0));
    }
}
